﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class TaiKhoanDao
    {
        public IEnumerable<TAIKHOAN> TimKiem(string ID, string Pass)
        {
            DoixeDataContext TV = new DoixeDataContext();
            IEnumerable<TAIKHOAN> tkDto;
            tkDto = from tk in TV.TAIKHOANs where tk.ID == ID && tk.MatKhau == Pass select tk;
            return tkDto;
        }
        public IEnumerable<TAIKHOAN> DanhSach()
        {
            DoixeDataContext TV = new DoixeDataContext();
            return TV.TAIKHOANs;
        }
        public IEnumerable<TAIKHOAN> Tim(string ID)
        {
            DoixeDataContext TV = new DoixeDataContext();
            IEnumerable<TAIKHOAN> tkDto;
            tkDto = from tk in TV.TAIKHOANs where tk.ID == ID select tk;
            return tkDto;
        }
        public void TaoTaiKhoan(TAIKHOAN TaiKhoan)
        {
            DoixeDataContext TV = new DoixeDataContext();
            TV.TAIKHOANs.InsertOnSubmit(TaiKhoan);
            TV.SubmitChanges();
        }
        public void XoaTaiKhoan(TAIKHOAN TaiKhoan)
        {
            DoixeDataContext TV = new DoixeDataContext();
            IEnumerable<TAIKHOAN> tkDto;
            tkDto = from tk in TV.TAIKHOANs where tk.ID == TaiKhoan.ID select tk;
            TV.TAIKHOANs.DeleteOnSubmit(tkDto.Single());
            TV.SubmitChanges();
        }
        public string LayMatKhau(string ID)
        {
            DoixeDataContext TV = new DoixeDataContext();
            IEnumerable<TAIKHOAN> tkDto;
            tkDto = from tk in TV.TAIKHOANs where tk.ID == ID select tk;
            return tkDto.Single().MatKhau;
        }
        public void DoiMatKhau(string ID, string MK)
        {
            DoixeDataContext TV = new DoixeDataContext();
            TAIKHOAN tkDto;
            tkDto = TV.TAIKHOANs.Single(tk => tk.ID == ID);
            tkDto.MatKhau = MK;
            TV.SubmitChanges();
        }
    }
}
